//
//  SecondWebViewViewController.m
//  YFZShoppingMall
//
//  Created by 梁晖 on 2017/9/15.
//  Copyright © 2017年 BJY12. All rights reserved.
//

#import "SecondWebViewViewController.h"
#import "UIBarButtonItem+CommomBarButtonItem.h"
#import "AppConfig.h"
#import "YBPopupMenu.h"

#define TITLES @[@"首页", @"帮助", @"分享",]
#define ICONS  @[@"pop_main",@"pop_help",@"pop_share"]
@interface SecondWebViewViewController ()<YBPopupMenuDelegate>
@property (nonatomic, strong) UIButton *backBtn;
@property (nonatomic, strong) UIButton *rightBtn;
@property (nonatomic, strong) YBPopupMenu *popupMenu;
@end

@implementation SecondWebViewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [baseWebView.scrollView setContentInset:UIEdgeInsetsMake(0,0,0,0)];
    // Do any additional setup after loading the view.
     [baseWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.listString]]];
    
    [self.view addSubview:self.backBtn];
    [self.view addSubview:self.rightBtn];
}

- (UIButton *)backBtn {
    if (!_backBtn) {
        _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_backBtn setTitle:@" " forState:UIControlStateNormal];
        _backBtn.frame = CGRectMake(10, 10, 40, 40);
        [_backBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    }
    return _backBtn;
}

- (UIButton *)rightBtn {
    if (!_rightBtn) {
        _rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_rightBtn setTitle:@" " forState:UIControlStateNormal];
        _rightBtn.frame = CGRectMake(SCREEN_WIDTH - 50 , 10, 40, 40);
        [_rightBtn addTarget:self action:@selector(rightAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rightBtn;
}

- (void)back
{
    // 最低控制器无需返回
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)rightAction:(id)sender {
//     [YBPopupMenu showRelyOnView:sender titles:TITLES icons:ICONS menuWidth:100 delegate:self];
    
    //推荐用这种写法
    
    CGPoint p = CGPointMake(SCREEN_WIDTH-25, 15);
    [YBPopupMenu showAtPoint:p titles:TITLES icons:ICONS menuWidth:110 otherSettings:^(YBPopupMenu *popupMenu) {
        popupMenu.dismissOnSelected = NO;
        popupMenu.isShowShadow = YES;
        popupMenu.delegate = self;
        popupMenu.offset = 20;
        popupMenu.type = YBPopupMenuTypeDefault;
        
        popupMenu.rectCorner = UIRectCornerBottomLeft | UIRectCornerBottomRight|UIRectCornerTopLeft|UIRectCornerTopRight;
        _popupMenu = popupMenu;
    }];
}

#pragma mark - YBPopupMenuDelegate
- (void)ybPopupMenuDidSelectedAtIndex:(NSInteger)index ybPopupMenu:(YBPopupMenu *)ybPopupMenu
{
    switch (index) {
        case 0:
        {
             [baseWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://m.zlc99.com/"]]];
        }
            break;
        case 1:
        {
             [baseWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://m.zlc99.com/help/index.html"]]];
        }
            break;
        case 2:
        {
             [baseWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://m.zlc99.com/account/invitationreg.html"]]];
        }
            break;
            
        default:
            break;
    }
    [_popupMenu dismiss];
}

@end
